﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;  ///系统配置包在配置文件中设置数据库连接时必须用
//using System.Configuration;
public partial class search_info : System.Web.UI.Page
{
    //已在web.config文件中配置数据库文件
    public static string constr = ConfigurationManager.ConnectionStrings["Web_ExperimentConnectionString"].ConnectionString;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GridView1.Visible = false;
            GridView2.Visible = false;
            GridView3.Visible = false;
        }
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        //查询老师信息
        GridView2.Visible = true;
        SqlConnection conn = new SqlConnection(constr);
        conn.Open();
        string SqlStr = "select * from teacher";
        SqlDataAdapter da = new SqlDataAdapter(SqlStr, conn);
        DataSet ds = new DataSet();
        da.Fill(ds, "teacher");
        //绑定DataList控件
        GridView2.DataSource = ds;
        GridView2.DataKeyNames = new string[] { "tno" };
        GridView2.DataBind();
        conn.Close();

        //隐藏GridView
        GridView1.Visible = false;
        GridView3.Visible = false;
    }

    protected void LinkButton1_Click2(object sender, EventArgs e)
    {
        //查询学生信息
        GridView1.Visible = true;
        SqlConnection conn = new SqlConnection(constr);
        conn.Open();
        //string SqlStr = "select * from student where sno='" + "201801" + "'";
        string SqlStr = "select * from student";
        SqlDataAdapter da = new SqlDataAdapter(SqlStr, conn);
        DataSet ds = new DataSet();
        da.Fill(ds, "student");

        //绑定DataList控件
        GridView1.DataSource = ds;
        GridView1.DataKeyNames = new string[] { "sno" };
        GridView1.DataBind();
        conn.Close();


        GridView2.Visible = false;
        GridView3.Visible = false;
    }


    protected void LinkButton3_Click1(object sender, EventArgs e)
    {
        //查询课表信息
        GridView3.Visible = true;
        string str = "Server=HXM-PC;integrated security=SSPI; DataBase=Web_Experiment;";
        SqlConnection conn = new SqlConnection(str);
        conn.Open();
        string SqlStr = "select * from course";
        SqlDataAdapter da = new SqlDataAdapter(SqlStr, conn);
        DataSet ds = new DataSet();
        da.Fill(ds, "course");

        //绑定datalist控件
        GridView3.DataSource = ds;
        GridView3.DataKeyNames = new string[] { "cno" };
        GridView3.DataBind();
        conn.Close();

        //隐藏GridView1
        GridView1.Visible = false;
        GridView2.Visible = false;
    }

    

    protected void GridView3_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void Button1_Click1(object sender, EventArgs e)
    {
        //按学号查询信息
        if (GridView1.Visible)
        {
            string str = "Server=HXM-PC;integrated security=SSPI; DataBase=Web_Experiment;";
            SqlConnection conn = new SqlConnection(str);
            conn.Open();
            string SqlStr = "select * from student where sno='" + TextBox1.Text.ToString() + "'";
            SqlDataAdapter da = new SqlDataAdapter(SqlStr, conn);
            DataSet ds = new DataSet();
            da.Fill(ds, "student");

            //绑定DataList控件
            GridView1.DataSource = ds;
            GridView1.DataKeyNames = new string[] { "sno" };
            GridView1.DataBind();
            conn.Close();
        }
        //按职工号查询
        if (GridView2.Visible)
        {
            string str = "Server=HXM-PC;integrated security=SSPI; DataBase=Web_Experiment;";
            SqlConnection conn = new SqlConnection(str);
            conn.Open();
            string SqlStr = "select * from teacher where tno='" + TextBox1.Text.ToString() + "'";
            SqlDataAdapter da = new SqlDataAdapter(SqlStr, conn);
            DataSet ds = new DataSet();
            da.Fill(ds, "teacher");

            //绑定DataList控件
            GridView2.DataSource = ds;
            GridView2.DataKeyNames = new string[] { "tno" };
            GridView2.DataBind();
            conn.Close();
        }
        //按课程号查询
        if (GridView3.Visible)
        {
            string str = "Server=HXM-PC;integrated security=SSPI; DataBase=Web_Experiment;";
            SqlConnection conn = new SqlConnection(str);
            conn.Open();
            string SqlStr = "select * from course where cno='" + TextBox1.Text.ToString() + "'";
            SqlDataAdapter da = new SqlDataAdapter(SqlStr, conn);
            DataSet ds = new DataSet();
            da.Fill(ds, "course");

            //绑定DataList控件
            GridView3.DataSource = ds;
            GridView3.DataKeyNames = new string[] { "cno" };
            GridView3.DataBind();
            conn.Close();
        }
    }
}